let reg_v = new Vue({
    el:"#reg_box",
    data:{
        mail:"",
        i1_sp:"1",
        pass1:"",
        pass2:"",
        tel:"",
        vcIn:"",
        vc:"",
        getVerifyCode:""
    },
    methods:{
        check1:function () {
            let EM = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            if(!EM.test(reg_v.mail)){
                layer.tips('邮箱格式有误,请重新输入!', '#i1_em');
                reg_v.mail="";
                return;
            }
            //发出异步请求
            axios.get("/reg/check1?mail="+reg_v.mail).then(function (response) {
                if(response.data == 1){
                    layer.tips('邮箱已存在请重新输入!', '#i1_em');
                    reg_v.mail = "";
                }
                if(response.data == 0){
                    reg_v.i1_sp = response.data;
                }
            })
        },
        check2:function () {
            if(reg_v.pass1.length<3){
                layer.tips('密码长度太短,请重新输入!', '#i2_pw');
                reg_v.pass1="";
            }
        },
        check3:function () {
            if(reg_v.pass1 != reg_v.pass2){
                layer.tips('两次输入密码不同,请重新输入!', '#i3_pw');
                reg_v.pass2="";
            }
        },
        check4:function () {
            let tel=/^1[345789]\d{9}$/;
            if(!tel.test(reg_v.tel)){
                layer.tips('手机号码格式错误,请重新输入!', '#i4_tel');
                reg_v.tel="";
            }
        },
        reg:function () {
            /*sweetAlert("恭喜您注册成功!", "欢迎您的加入,点击按钮将跳转登录页面!", "success");*/
            let data = new FormData(document.querySelector("form"));
            axios.post("/reg",data).then(function (response) {
                if (response.data==1){
                    swal("恭喜您注册成功!", "点击按钮将跳转登录页面!", "success").then(() => {
                        location.href="/login.html";
                    });
                    return;
                }
                if (response.data==2){
                    swal("验证码错误,请重新输入!");
                    reg_v.vcIn = "";
                    return;
                }
                swal("注册失败!", "用户名已存在,请重新输入用户名!");
                reg_v.mail = "";
            })
        }

    },
    created:function () {
        let rm = parseInt(Math.random()*100) + 1;
        axios.get("/obtainVC?vcid="+rm).then(function (response) {
            reg_v.vc = response.data;
        })
    }
})